package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class UserMappingHotel extends AbstractData {
	private long id = -1;
	//private long displayId;
	private String userString;
	private User user;
	private String userlevelString;
	private UserLevel userlevel;
	private long hotelId;
	private Department department;
	private String departmentString;
	private boolean status;
	private boolean avaliable;
	
	public long getHotelId() {
		return hotelId;
	}
	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}

//	public long getDisplayId() {
//		return displayId;
//	}
//	public void setDisplayId(long displayId) {
//		this.displayId = displayId;
//	}
	
	public String getUserString() {
		return userString;
	}
	
	public void setUserString(String userString) {
		this.userString = userString;
	}
	
	public User getUser() {
		if (user == null
				&& !(userString == null || userString.isEmpty())) {
				User p = new User(Long.parseLong(userString));
			p.LoadData();
			user = p;
		}
		return user;
	}
	
	public void setUser(User user) {
		this.userString = String.format("%d", user.getId());
		this.user = user;
	}
	
	public String getUserlevelString() {
		return userlevelString;
	}
	
	public void setUserlevelString(String userlevelString) {
		this.userlevelString = userlevelString;
	}
	public UserLevel getUserlevel() {
		if (userlevel == null
			&& !(userlevelString == null || userlevelString.isEmpty())) {
			UserLevel p = new UserLevel(Long.parseLong(userlevelString));
		p.LoadData();
		userlevel = p;
	}
		return userlevel;
	}
	public void setUserlevel(UserLevel userlevel) {
		this.userlevelString = String.format("%d", userlevel.getId());
		this.userlevel = userlevel;
	}

	public Department getDepartment() {
		if (department == null && !(departmentString == null || departmentString.isEmpty())) {
			Department d = new Department(Long.parseLong(departmentString));
			d.LoadData();
			department = d;
		}
		return department;
	}

	public void setDepartment(Department department) {
		this.departmentString = String.format("%d", department.getId());
		this.department = department;
	}
	public String getDepartmentString() {
		return departmentString;
	}
	public void setDepartmentString(String departmentString) {
		this.departmentString = departmentString;
	}
	public boolean isStatus() {
		return status;
	}
	public void setStatus(boolean status) {
		this.status = status;
	}
	public boolean isAvaliable() {
		return avaliable;
	}
	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}
	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.UserMappingHotel);
		else
			item = new Entity(this.key);
		//item.setProperty("displayId", this.displayId);
		item.setProperty("hotelId", this.hotelId);
		item.setProperty("userId", this.userString);
		item.setProperty("userlevel", this.userlevelString);
		item.setProperty("departmentString", this.departmentString);
		item.setProperty("status", this.status);
		item.setProperty("avaliable", this.avaliable);
		return item;
	}
	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		//this.displayId = (Long) entity.getProperty("displayId");
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.userString = (String) entity.getProperty("userId");
		if(entity.getProperty("userlevel") == null){
			this.userlevelString = "0";
		}else{
			this.userlevelString = (String) entity.getProperty("userlevel");
		}
		this.departmentString = (entity.getProperty("departmentString")!=null)?(String) entity.getProperty("departmentString"):null;
		this.status = (Boolean) entity.getProperty("status");
		this.avaliable = (Boolean) entity.getProperty("avaliable");
		this.key = entity.getKey();
	}

	public void LoadData()
	{
		if(this.id > -1)
		{
			Entity entity = LoadData(EntityName.UserMappingHotel,this.id);
			setEntity(entity);
		}
	}
}
